<?php
if (!defined('W_ROOT')) {
	exit();
}
$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
?>
<div class="breadcrumb">
        <a href="<?php echo base_url_admin;?>"><?php echo $lang['HOME'];?></a>
         ::<?php echo $lang['LIST_PAGE'];?>
      </div>
       <div class="box">
<?php 

	$messageSuccess = isset($_GET['message'])?$_GET['message']:"";
	if(!empty($messageSuccess) && $messageSuccess=='add'){
		?>
		<div  class="success"><?php echo $lang['MESSAGE_UPDATE'];?></div>
		<?php 
	}
	if(!empty($messageSuccess) && $messageSuccess=='update'){
		?>
		<div class="success">Page has been updated!</div>
		<?php 
	}
	if(!empty($messageSuccess) && $messageSuccess=='del'){
		?>
		<div class="warning">Page has been deleted!</div>
		<?php 
	}
	
	
?>
<div class="heading">
	<h1><img src="../templates/image/order.png" alt="" />
		<?php 
			echo $lang["PAGE"];
		?>
	</h1>
	<form action="" method="post" enctype="multipart/form-data" id="form">
	<div class="buttons">
	<a href="<?php echo base_url_admin;?>/pages/index.php?view=add" class="button"><?php echo $lang['INSERT'];?></a>
	<a href="javascript:;" class="button" id="OnDelete"><?php echo $lang['DELETE'];?></a></div>
	<div style="display:none; float:right; padding-top:7px;" id="deleteSucess_1"><img src="../images/load.gif" /></div>
	<script type="text/javascript">
	$(document).ready(function(){
		 
		$('#OnDelete').on('click',function(){
			 $('#deleteSucess_1').fadeIn();
			 $('#deleteSucess').hide();
			var checkId = $('.check_box:checked').map(function(){
					return this.value;
				}).get().join(',');
			if(checkId==''){
					alert("<?php echo $lang['MESSAGE_SELECT'];?>");
				}
			  $.ajax
              ({
                  type: "GET",
                  url: "check.php",
                  data: {checkId:checkId},
                  cache: false,
                  success: function(html)
                  {
                      if(html){
                          $('#delsucess').html(html);
                          $('#deleteSucess_1').fadeOut();
                      }
					$("#loading").fadeOut(200);
                  }
              });
			});
		});
	</script>
</div>
<SCRIPT language="javascript">
		$(function(){
		
			// add multiple select / deselect functionality
			$("#chkall").click(function () {
				  $('.check_box').attr('checked', this.checked);
			});
		
			// if all checkbox are selected, check the selectall checkbox
			// and viceversa
			$(".check_box").click(function(){
		
				if($(".check_box").length == $(".check_box:checked").length) {
					$("#chkall").attr("checked", "checked");
				} else {
					$("#chkall").removeAttr("checked");
				}
		
			});
		});
</SCRIPT>
    <div id="delsucess"></div> 
    <div id="deleteSucess" style="display:none;"><?php echo $lang['MESSAGE_DELETE_SUCCESS'];?></div> 
	<div class="content">
	<form action="" method="post" enctype="multipart/form-data" id="form">
		<table class="list">
			<thead>
				<tr>
				
					<td width="1"><?php echo $lang['N']; ?></td>
					<td class="left"><input type="checkbox" name="chkall[]" id="chkall" onClick="checkAll(this.form,this.checked)" style="cursor:pointer;"></td>
					<td class="center" ><?php echo $lang['PAGE_NAME']; ?></td>
					<td class="center" ><?php echo $lang['ACC_ID']; ?></td>
					<td class="center"><?php echo $lang['ORDERING']; ?></td>
					<td class="center"><?php echo $lang['STATUS']; ?></td>
					<td class="center"><?php echo $lang['CRETE_DATE']; ?></td>
					<td class="center"><?php echo $lang['MODI_DATE']; ?></td>
					<td class="center"><?php echo $lang['OTHER']; ?></td>
					
				</tr>
		</thead>
		<tbody>
		
		<?php
				$page = '';
				$per_page = 10;
				if(isset($_GET['page']))
				{
					$page=$_GET['page'];
					$start = ($page-1)*$per_page;
				}else{
					$start = 0;
				}
				$sql = "SELECT * FROM ".Tblpage::tblpages." ORDER BY ".Tblpage::id." DESC limit $start,$per_page";
				$result= mysql_query($sql);
				$i = 1;
				$j = 0;
				while($row = mysql_fetch_assoc($result)){
					extract($row);
					if($i%2){
						$class = 'row1';
					}else{
						$class = 'row2';
					}
					$i++;
					$j++;
				
		?>
		<tr id="page<?php echo $row[Tblpage::id]; ?>">
			<td class="left"><?php echo $j;?></td>
			<td class="left"><input type="checkbox" class="check_box" id="chk" class="check_box" name="id[]" value="<?php echo $row['id'];?>" /></td></td>
			<td class="left"><?php 	echo $row[Tblpage::name]; ?></td>
			<td class="left"><?php echo $row[Tblpage::id]; ?></td>
			<td class="left"><?php echo $row[Tblpage::ordering]; ?></td>
			<td class="left"><?php echo stateImage($row[Tblpage::id],$row[Tblpage::status]);?></td>
			<td class="left"><?php echo $row[Tblpage::create_date]; ?></td>
			<td class="left"><?php echo $row[Tblpage::modify_date]; ?></td>
			<td class="center"><a href="index.php?view=add&amp;id=<?php echo $id;?>"><img width="20" src="../templates/image/Edit.gif" alt="<?php echo $lang['EDIT'];?>" /></a>
			<a onclick="return ConfirmDelete('<?php echo base_url_admin;?>/pages/index.php?view=delete&amp;id=<?php echo $id;?>')" href="javascript:;"><img width="20" src="../templates/image/trash.png" alt="<?php echo $lang['DELETE'];?>" /> </a> 
			</td>
		</tr>
		<?php }?>
		</tbody>
		</table>
		</form>
		<?php 
				$pages = '';
				$per_page = 10; 
				$select_table = "SELECT * FROM ".Tblpage::tblpages;
				$variable = mysql_query($select_table);
				$count = mysql_num_rows($variable);
				$pages = ceil($count/$per_page);
			
		?>
		<div class="pagination">
		
		<div class="links">
		<?php
		if($pages!=1){
		for($i=1; $i<=$pages; $i++){
		?>
		<a href="index.php?page=<?php echo $i;?>"><b><?php echo $i;?></b></a>
		<?php 
			}
		}
		?>
		 </div>
			<div class="results">
					<?php 
						echo $lang['SHOWING'].'1 to 10 of '.$count." (".@$_GET['page']." Page)";
					?>
			</div>
		</div>
		</div>
		</div>